/*
 * @Author: huangyq
 * @Date: 2022-04-20 14:40:20
 * @LastEditTime: 2022-04-21 15:02:22
 * @LastEditors: huangyq
 * @Description: 权限指令 v-auth
 * @FilePath: /vue3-boilerplate-pc-client/src/directives/vAuth.ts
 */
import { App } from 'vue'
import { usePermissionStore } from '@/stores/permission'

function vAuth(el: Element, binding: any) {
  const { checkPermissionByCode } = usePermissionStore()
  const value = binding.value
  if (!value) return
  if (!checkPermissionByCode(value)) {
    el.parentNode?.removeChild(el)
  }
}

export default function AuthDirective(app: App) {
  app.directive('auth', {
    mounted: vAuth
  })
}
